package demo;

import java.util.Scanner;

public class SmartHomeControl
{
        public void showAllJD(JD jds[])
        {
            while(true)
            {
            int i = 0;
            for(i = 0;i<jds.length;i++)
            {
                JD jd = jds[i];
                System.out.println((i+1)+","+jd.getName() + "状态目前是：" + (jd.isStatus() ? "开着" : "关着"));
            }


                System.out.println("请选择你想操作的家电：");
                Scanner sc = new Scanner(System.in);
                String command = sc.next();
                switch(command)
                {
                    case "1":
                        control(jds[0]);
                        break;
                    case "2":
                        control(jds[1]);
                        break;
                    case "3":
                        control(jds[2]);
                        break;
                    case "4":
                        control(jds[3]);
                        break;
                    case "exit":
                        System.out.println("退出App");
                        return;
                    default:
                        System.out.println("输入错误，请重新输入");
                }
            }
        }


    public void control(JD jd)
    {
        System.out.println(jd.getName()+ "现在的状态是：" + (jd.isStatus() ?"开着" : "关着"));
        System.out.println("开始你的操作：。。。。。");
        jd.press();// 按一下开关
        System.out.println(jd.getName()+ "按下后：" + (jd.isStatus() ?"开着" : "关着"));
    }
}


